file chooser: Respect recent settings
authorMatthias Clasen <mclasen@redhat.com>
Sat, 30 May 2015 13:21:16 +0000 (09:21 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 30 May 2015 13:21:16 +0000 (09:21 -0400)
When recent files are not supported in gvfs, or turned off by
settings, we should not try to load them even if the startup
mode says so. This prevents inconsistency with the places
sidebar where 'Recent' will not appear in this case.

gtk/gtkfilechooserwidget.c

index be004bc3bc5003ee44a72a6abdf462df97c2da95..ea96292dd11accb092283d45b20b0edb748b2362 100644 (file)
@@ -3206,6 +3206,36 @@ switch_to_cwd (GtkFileChooserWidget *impl)
   g_free (current_working_dir);
 }
 
+static gboolean
+recent_files_setting_is_enabled (GtkFileChooserWidget *impl)
+{
+  GtkSettings *settings;
+  gboolean enabled;
+
+  settings = gtk_widget_get_settings (GTK_WIDGET (impl));
+  g_object_get (settings, "gtk-recent-files-enabled", &enabled, NULL);
+
+  return enabled;
+}
+
+static gboolean
+recent_scheme_is_supported (void)
+{
+  const gchar * const *supported;
+
+  supported = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
+  if (supported != NULL)
+    return g_strv_contains (supported, "recent");
+
+  return FALSE;
+}
+
+static gboolean
+can_show_recent (GtkFileChooserWidget *impl)
+{
+  return recent_files_setting_is_enabled (impl) && recent_scheme_is_supported ();
+}
+
 /* Sets the file chooser to showing Recent Files or $CWD, depending on the
  * user’s settings.
  */
@@ -3217,8 +3247,12 @@ set_startup_mode (GtkFileChooserWidget *impl)
   switch (priv->startup_mode)
     {
     case STARTUP_MODE_RECENT:
-      operation_mode_set (impl, OPERATION_MODE_RECENT);
-      break;
+      if (can_show_recent (impl))
+        {
+          operation_mode_set (impl, OPERATION_MODE_RECENT);
+          break;
+        }
+      /* else fall thru */
 
     case STARTUP_MODE_CWD:
       switch_to_cwd (impl);